(function () {
    angular
        .module('ita')
        .factory('ita.controller.TraineesService', TraineesService);

    TraineesService.$inject = ['$http'];

    function TraineesService($http) {
        return {
            findAllTrainee : findAllTrainee,
            addTrainee : addTrainee,
            getTraineeByDomainId:getTraineeByDomainId,
            updateTrainee:updateTrainee
        };

        function findAllTrainee(callback) {
            var request = {
                method: 'GET',
                url: '/ita/findAllTrainee'
            };
            
            return $http(request).success(function(data, status, headers) {
                callback(null, data);
            });
        }

        function addTrainee(callback){
            var request = {
                method: 'POST',
                url : '/ita/addTrainee'
            };

             return $http(request).success(function(data, status, headers) {
                callback(null, data);
            });
        }

        function getTraineeByDomainId(domainId, callback){
            var request = {
                method: 'GET',
                url : `/ita/getTraineeByDomainId/${domainId}`
            };

            return $http(request).success(function(data, status, headers){
                callback(null, data);
            });
        }

        function updateTrainee(trainee, callback){
            var request = {
                method: 'POST',
                url : `/ita/updateTrainee`,
                data: trainee
            };

            return $http(request).success(function(data, status, headers){
                callback(null, data);
            });
        }
    }
})();